import numpy as np


# 非门电路的设计和实现
def NAND(x1, x2):
    x = np.array([x1, x2])
    w = np.array([-0.5, -0.5])
    b = 0.7  # 偏置参数

    tmp = np.sum(x * w) + b
    if tmp <= 0:
        return 0
    else:
        return 1


# 程序入口
if __name__ == '__main__':
    for xs in [(0, 0), (0, 1), (1, 0), (1, 1)]:
        y = NAND(xs[0], xs[1])
        print(str(xs) + ' -> ' + str(y))  # 应该用变量来代替result
